#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright [Gtlions Lai].
# Create Date:
# Update Date:
"""summarization ahout this script.

detail ahout this script

   Class(): summarization about Class
   ...
   function(): summarization about function
   ...
"""
__authors__ = '"Gtlions Lai" <gtlions.l@qq.com>'

import sys
from PyQt4 import QtGui, QtCore


class Geometry(QtGui.QDialog):
    def __init__(self, parent=None):
        super(Geometry, self).__init__(parent)
        self.setWindowTitle('QWidget')
        self.setGeometry(300, 300, 300, 300)
        grid = QtGui.QGridLayout()
        # self.setLayout(grid)

        l1 = QtGui.QLabel("x0:")
        l2 = QtGui.QLabel("y0:")
        l3 = QtGui.QLabel("frameGeometry():")
        l4 = QtGui.QLabel("pos():")
        l5 = QtGui.QLabel("geometry():")
        l6 = QtGui.QLabel("width():")
        l7 = QtGui.QLabel("height():")
        l8 = QtGui.QLabel("rect():")
        l9 = QtGui.QLabel("size():")

        self.xl = QtGui.QLabel()
        self.yl = QtGui.QLabel()
        self.framel = QtGui.QLabel()
        self.posl = QtGui.QLabel()
        self.geol = QtGui.QLabel()
        self.wl = QtGui.QLabel()
        self.hl = QtGui.QLabel()
        self.rectl = QtGui.QLabel()
        self.sizel = QtGui.QLabel()

        layout = QtGui.QGridLayout()
        layout.addWidget(l1, 0, 0)
        layout.addWidget(self.xl, 0, 1)
        layout.addWidget(l2, 1, 0)
        layout.addWidget(self.yl, 1, 1)
        layout.addWidget(l3, 2, 0)
        layout.addWidget(self.framel, 2, 1)
        layout.addWidget(l4, 3, 0)
        layout.addWidget(self.posl, 3, 1)
        layout.addWidget(l5, 4, 0)
        layout.addWidget(self.geol, 4, 1)
        layout.addWidget(l6, 5, 0)
        layout.addWidget(self.wl, 5, 1)
        layout.addWidget(l7, 6, 0)
        layout.addWidget(self.hl, 6, 1)
        layout.addWidget(l8, 7, 0)
        layout.addWidget(self.rectl, 7, 1)
        layout.addWidget(l9, 8, 0)
        layout.addWidget(self.sizel, 8, 1)

        self.setLayout(layout)
        self.updatelabel()

    def moveEvent(self, event):
        self.updatelabel()

    def resizeEvent(self, event):
        self.updatelabel()

    def updatelabel(self):
        temp = QtCore.QString()
        """
        x(),y() 是从左上角开始，从上到下，从左到右计算的
        frameGeometry().x(),frameGeometry().y(),frameGeometry().width(),frameGeometry().height() 是窗口位置信息 对应 x y width height
        pos().x(),pos().y() 和 x(),y() 一样
        geometry().x()，geometry().y()，geometry().width()，geometry().height() 是窗口内部件相对于屏幕的位置信息
        width(),height() 是窗口的宽和高
        rect().x(),rect().y(),rect().width(),rect().height() 是窗口内部件相对于窗口的位置信息
        size().width(),size().height() 是窗口的大小信息,和width(),height()一样
        """
        self.xl.setText(temp.setNum(self.x()))
        self.yl.setText(temp.setNum(self.y()))
        self.framel.setText(
            temp.setNum(self.frameGeometry().x()) + "," + temp.setNum(self.frameGeometry().y()) + "," + temp.setNum(
                self.frameGeometry().width()) + "," + temp.setNum(self.frameGeometry().height()))
        self.posl.setText(temp.setNum(self.pos().x()) + "," + temp.setNum(self.pos().y()))
        self.geol.setText(temp.setNum(self.geometry().x()) + "," + temp.setNum(self.geometry().y()) + "," + temp.setNum(
            self.geometry().width()) + "," + temp.setNum(self.geometry().height()))
        self.wl.setText(temp.setNum(self.width()))
        self.hl.setText(temp.setNum(self.height()))
        self.rectl.setText(temp.setNum(self.rect().x()) + "," + temp.setNum(self.rect().y()) + "," + temp.setNum(
            self.rect().width()) + "," + temp.setNum(self.rect().height()))
        self.sizel.setText(temp.setNum(self.size().width()) + "," + temp.setNum(self.size().height()))

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = Geometry()
    main.show()
    sys.exit(app.exec_())